package com.webserver.core;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class ClientHandler implements Runnable{

    //通过创建ClientHandler属性socket,拿到与客户端连接的socket
    private Socket socket;

    public ClientHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //初始测试客户端发来的内容
        try {
            InputStreamReader reader =
                    new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8);
            int read;
            while ((read = reader.read()) != -1){
                System.out.print((char) read);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
